package com.woniu.adapter;

import com.woniu.outlet.mysql.BuyRateDao;
import com.woniu.outlet.mysql.po.BuyRateMySQL;
import com.woniu.outlet.mysql.po.BuyRateMySQLExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.List;

@Component
public class BuyRateAdapter {

    @Autowired
    private BuyRateDao buyRateDao;

    /**
     * 根据用户购买金额获取计算手续费的对象
     *
     * @param money 用户购买产品的金额
     * @return
     */
    public BuyRateMySQL getBuyRateMSQLByMoney(BigDecimal money) {
        BuyRateMySQL buyRateMySQL = null;
        BuyRateMySQLExample example = new BuyRateMySQLExample();
        if (money.longValue()>5000000){
            return buyRateDao.selectByPrimaryKey(4L);
        }
        example.createCriteria().andGreaterThanEqualLessThanOrEqualTo(money.longValue()/10000).andLessThanGreaterThan(money.longValue()/10000);
        List<BuyRateMySQL> buyRateMySQLS = buyRateDao.selectByExample(example);
        for (BuyRateMySQL rateMySQL : buyRateMySQLS) {
            buyRateMySQL = rateMySQL;
        }
        return buyRateMySQL;
    }

}
